<?php
    class Product_m extends Model{
        function Product_m(){
            parent::Model();
            $this->load->database();    
        }
        function get_all_animals($per_page,$offset){
            $this->db->select('animaux.id,animaux.nom,animaux.prix,animaux.img,categories.nomfr');
            $this->db->from('animaux');
            $this->db->join('categories', 'categories.id = animaux.catid');
            $this->db->order_by('id','DESC');
            $this->db->limit($per_page,$offset);
            $query=$this->db->get();
            return $query->result_array();
        }
        function get_all_counttries(){
            $query = $this->db->get('geo_countries');
            return $query->result_array();
        }
        function get_all_categories(){
            $query = $this->db->query('select * from categories where parent>0');
            return $query->result_array();
        }
        function add_animal($data){
            return $this->db->insert('animaux',$data);
        }
        function delete_animal($id){
            return $this->db->delete('animaux',array('id'=>$id));
        }
        function get_animal_by_id($id){
            $query = $this->db->get_where('animaux',array('id'=>$id));
            return $query;
        }                                
        function update_animal($data,$id){
            return $this->db->update('animaux',$data,array('id'=>$id));
        }
        function get_product_categories($per_page,$off_set){
            $this->db->select();
            $this->db->from('categories');
            $this->db->limit($per_page,$off_set);
            $query=$this->db->get();
            return $query->result_array();    
        }
        function add_category($data){
            return $this->db->insert('categories',$data);
        }
        function delete_category($id){
            return $this->db->delete('categories',array('id'=>$id));
        }
        function get_children($prent_id){    
            $this->db->select('id');
            $this->db->from('categories');
            $this->db->where(array('parent'=>$prent_id));
            $query = $this->db->get();
            return $query->result_array();
        }
        function get_cat_image($id){
            $this->db->select('img');
            $this->db->from('categories');
            $this->db->where(array('id'=>$id));
            $query = $this->db->get();
            return $query;
        }
        function get_cat_by_id($id){
            $query=$this->db->get_where('categories',array('id'=>$id));
            return $query;
        }
        function update_categorie($data,$id){
            return $this->db->update('categories',$data,array('id'=>$id));
        }
    }
?>
